import java.awt.BorderLayout;

import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class table extends JComponent {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JTable dbTable;
	JScrollPane jsp;
	
	/*
	 * as we know this is need to be a static model, so do not change it.
	 * it the main table-filling process we are filling out this table with
	 * the result of MySql query
	 */
	static DefaultTableModel model[] = new DefaultTableModel[10];
	
	public table(final Integer index) {
		
		//first we are filling with
		String[] emptyRow = null;
		
		System.out.println("Setting up model[" + index + "]");
		
		//create an empty table model and assign it to the table
		model[index] = new DefaultTableModel();
		System.out.println("Model[" + index + "] has been set up");
		dbTable = new JTable(model[index]);

		/*
		 * setting the main layout for the table, and adding it to the scroll
		 * pane
		 */
		dbTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		setLayout(new BorderLayout());
		jsp = new JScrollPane(dbTable);
		add(jsp, BorderLayout.CENTER);
		
		//filling out the tables wit some demo entries
		model[index].addColumn("left");
		model[index].addColumn("rigth");
		
		model[index].addRow(emptyRow);
		model[index].addRow(emptyRow);
		
		model[index].setValueAt("holly", 0, 0);
		model[index].setValueAt("molly", 0, 1);
		
		model[index].setValueAt("status", 1, 0);
		model[index].setValueAt("quoe", 1, 1);
	}
	
	public static String[] fillTableCols(Integer a, Integer index) {
		
		String[] colNames = new String[a];
		
		for(int i = 0; i < a; i++) {
			model[index].addColumn(a.toString());
			colNames[i] = a.toString();
			System.out.println("colNames[" + i + "] = " + a);
		}
		
		return colNames;
	}
	
}